package com.tanhua.server.service;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.sun.org.apache.regexp.internal.RE;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.server.vo.TodayBest;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class
RecommendUserService {

    @Reference//通过dubbo跟recommendUserApi交互获取数据
    RecommendUserApi recommendUserApi;
    public TodayBest queryTodayBast(Long id) {
        RecommendUser recommendUser = recommendUserApi.queryWithMaxScore(id);
        System.out.println(recommendUser);
        if (recommendUser==null){
            return null;
        }
        TodayBest todayBest = new TodayBest();
        Long userId = recommendUser.getUserId();//推荐ID
        todayBest.setId(userId);
        //获取缘分值
        double floor = Math.floor(recommendUser.getScore());
        todayBest.setFateValue(Double.valueOf(floor).longValue());
        return todayBest;
    }

    public PageInfo<RecommendUser> queryRecommendUserList(Long id, Integer page, Integer pagesize) {
        PageInfo<RecommendUser> pageInfo = recommendUserApi.queryPageInfo(id, page, pagesize);
        return pageInfo;
    }
    //获取缘分值
    public Double queryScore(Long userId, Long toUserId) {
        Double score = this.recommendUserApi.queryScore(userId, toUserId);
        if (ObjectUtil.isNotEmpty(score)) {
            double floor = Math.floor(score);
            return floor;
        }
        return 98D;
   }

    public List<RecommendUser> queryCardList(Long userId, int count) {
        return this.recommendUserApi.queryCardList(userId,count);
    }
}
